package ntd.util.frame.action.function.map;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import ntd.action.ActionAbs;
import ntd.action.bo.ActionInfo;
import ntd.action.bo.ActionOutBo;
import ntd.util.modular.function.entity.ChannelBusiness;
import ntd.util.modular.function.util.UtilChannelBusiness;

public class ActionAreaList extends ActionAbs {

    @Override
    public ActionInfo info() {
        return new ActionInfo("区域信息列表", "action-area-list", new ActionAreaList());
    }

    @Override
    public ActionOutBo handle() {
        

        String dataCode = actionInBo.getDataCode();

        ChannelBusiness channelBusiness = UtilChannelBusiness.getById(dataCode);

        return new ActionOutBo(listArea(channelBusiness));
    }

    private static String listArea(ChannelBusiness channelBusiness) {
        switch (channelBusiness.getEnumPlatformType()) {
            case MAP_TDT: {
                String res = HttpUtil.get(StrUtil
                        .format("http://api.tianditu.gov.cn/administrative?postStr={\"searchWord\":\"156000000\",\"needSubInfo\":\"true\",\"needAll\":\"true\"}&tk={}", channelBusiness.getAppKey()));
                return JSONUtil.parseObj(res).getStr("data");
            }
        }
        return "";
    }

}
